<?php
declare (strict_types=1);

namespace app\user\service;

use app\model\Chat;
use app\model\ChatLog;
use app\model\Kefu;

class ChatService extends \think\Service
{
    /**
     * 添加聊天记录
     * @param $data
     * @return ChatLog
     * @author dgc<453342213@qq.com>
     * createTime:2020/9/3 13:38
     */
    public static function addLog($data)
    {
        $model = new ChatLog();
        $model->save($data);
        return $model;
    }
    /**
     * 匹配会话客服
     * @param $data
     * @author dgc<453342213@qq.com>
     * createTime:2020/9/3 13:57
     */
    public static function matchingChatKefu($info)
    {
        if ($info['kefu_id'] == 0) {
            //-----------下面自己写匹配客服规则 (我这里随便弄一个)
            $kefu = Kefu::where('status', 1)->field('id,name,head,login_status,fd')->find();
        } else {
            $kefu = Kefu::where('id', $info['kefu_id'])->field('id,name,head,login_status,fd')->find();
        }
        $kefu = $kefu->toArray();
        $kefu['chat_id'] = $info->id;
        return $kefu;
    }
}
